﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace SystemModule
{
    /// <summary>
    /// 加载玩家数据结构体
    /// </summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public class TLoadHuman
    {
        /// <summary>
        /// 会话ID
        /// </summary>
        public int nSessionID;
        /// <summary>
        /// 玩家帐号
        /// </summary>
        public string sAccount;
        /// <summary>
        /// 玩家名称
        /// </summary>
        public string sChrName;
        /// <summary>
        /// 玩家IP地址
        /// </summary>
        public string sUserAddr;

        public byte[] ToByte()
        {
            using (var memoryStream = new MemoryStream())
            {
                var backingStream = new BinaryWriter(memoryStream);
                backingStream.Write(sAccount.ToByte(13));
                backingStream.Write(sChrName.ToByte(15));
                backingStream.Write(sUserAddr.ToByte(16));
                backingStream.Write(nSessionID);
                var stream = backingStream.BaseStream as MemoryStream;
                return stream.ToArray();
            }
        }
    }
}